/* TMDEFS.H
 * OPENMV definitions.
 * Copyright (c) 2007 MissingNODE 
 * Based on GPL OpenQM Code
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * 
 * 
 * START-HISTORY:
 * Oct-10-2007 Initial Revision
 * END-HISTORY
 *
 * START-DESCRIPTION:
 *
 * END-DESCRIPTION
 *
 * START-CODE
 */
#ifndef __TMDEFS
#define __TMDEFS

   #define _XOPEN_SOURCE
   #define _XOPEN_CRYPT
   #include <unistd.h>
   #include <endian.h>
   #if __BYTE_ORDER == __BIG_ENDIAN
      #define BIG_ENDIAN_SYSTEM
   #endif
   #define environ __environ

   #define Seek(fu, offset, whence) lseek(fu, offset, whence)




/* Derived items */

   #define DS '/'
   #define DSS "/"
   #define Newline "\n"
   #define NewlineBytes 1

   #define OSFILE int
   #define default_access 0666
   #define O_BINARY 0
   #define O_TEXT 0
   #define FOPEN_READ_MODE "r"
   #define FOPEN_WRITE_MODE "w"
   #define NULL_DEVICE "/dev/null"

   #define ALIGN2 __attribute__ ((aligned(2),packed))

   #define MakeDirectory(path) mkdir(path, 0777)
#define TM_SHM_KEY 0x716d0101
#define TM_SEM_KEY 0x716d0102

#ifndef DS
        #error No Enviornment Set
#endif

#define MAX_PATHNAME_LEN         255
#define MAX_ID_LEN               255
#define MAX_CALL_NAME_LEN        63
#define MAX_TRIGGER_NAME_LEN     32
#define MAX_PROGRAM_NAME_LEN     128
#define MAX_USERNAME_LEN         32
#define MAX_MATCH_TEMPLATE_LEN   256
#define MAX_MATCHED_STRING_LEN   8192
#define MAX_PACKAGES             32
#define MAX_PACKAGE_NAME_LEN     15
#define MAX_ACCOUNT_NAME_LEN     32
#endif

#define private static
#ifndef public
        #define public extern
#endif

#ifndef init
        #define init(a)
#endif

/** Type Definitions **/
typedef short int bool;
#define FALSE 0
#define TRUE 1


typedef long long int64;
typedef unsigned long long u_int64;

#ifdef BIG_ENDIAN_SYSTEM
     short int swap2(short int n);
     long int swap4(long int n);
     #define ShortInt(n) swap2(n)
     #define LongInt(n) swap4(n)
#else
     #define ShortInt(n) (n)
     #define LongInt(n) (n)
#endif

public u_char uc_chars[256];
public u_char lc_chars[256];

#define UpperCase(c) (uc_chars[(unsigned char)(c)])
#define LowerCase(c) (lc_chars[(unsigned char)(c)])

public u_char char_types[256];
#define CT_ALPHA 0x01
#define CT_DIGIT 0x02
#define CT_GRAPH 0x04
#define CT_MARK  0x08
#define CT_DELIM 0x10

#define IsAlnum(c) (char_types[(short int)(c)] & (CT_ALPHA | CT_DIGIT))
#define IsAlpha(c) (char_types[(short int)(c)] & CT_ALPHA)
#define IsDigit(c) (char_types[(short int)(c)] & CT_DIGIT)
#define IsGraph(c) (char_types[(short int)(c)] & CT_GRAPH)
#define IsDelim(c) (char_types[(short int)(c)] & CT_DELIM)
#define IsMark(c)  (char_types[(short int)(c)] & CT_MARK)

/** Collation map **/
public u_char * collation_map_name init(NULL);
public u_char * collation init(NULL);

#define SortCompare(s1,s2,n,nocase) ((nocase)?MemCompareNoCase(s1,s2,n):memcmp(s1,s2,n))

#define TEXT_MARK             ((u_char)'\xFB')
#define SUBVALUE_MARK         ((u_char)'\xFC')
#define VALUE_MARK            ((u_char)'\xFD')
#define FIELD_MARK            ((u_char)'\xFE')
#define ITEM_MARK             ((u_char)'\xFF')

#define TEXT_MARK_STRING               "\xFB"
#define SUBVALUE_MARK_STRING           "\xFC"
#define VALUE_MARK_STRING              "\xFD"
#define FIELD_MARK_STRING              "\xFE"
#define ITEM_MARK_STRING               "\xFF"
